<template>
  <!-- table区域-begin -->
  <div>
    <vxe-grid
      style="width: 100%;"
      :height="320"
      size="mini"
      align="center"
      highlight-hover-row
      stripe
      row-key
      row-id="selectedRowKeys"
      column-min-width="150"
      id="id"
      keep-source
      :loading="loading"
      border
      resizable
      showOverflow
      showHeaderOverflow
      :pager-config="tablePage"
      ref="xGrid"
      :row-config="{ useKey: true,keyField: 'id',isCurrent:true,isHover:true}"
      :checkbox-config="{
          checkRowKeys:selectedRowKeys,
          trigger: 'row',
          highlight: true,
          reserve: true}"
      @sort-change="sortChange"
      @checkbox-change="checkboxChangeEvent"
      @checkbox-all="checkboxChangeEvent"
      :data="dataSource"
      :columns="columns"
      @page-change="handlePageChange"
    >
      <template v-slot:top>
        <!-- 操作按钮区域 -->
        <div class="table-operator" v-if="(selectObj.id && !disabled)">
          <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
          &nbsp;
          <a-tooltip>
            <template #title>
              1：设备有特殊读写协议的如提升机,RGV,机械手等设备,设备无需配置坐标工位
              2：设备有点位的需维护坐标或者工位信息
            </template>
            <a-icon style="font-size: 22px;color: #00DB00" type="question-circle-o"></a-icon>
          </a-tooltip>
        </div>
      </template>
      <template v-slot:operate="{ row }">
        <a-button type="primary" shape="circle" @click="handleEdit(row)" icon="edit"/>
        <a-divider type="vertical"/>
        <a-dropdown>
          <a-button type="primary" shape="circle" class="ant-dropdown-link" icon="setting"/>
          <a-menu slot="overlay">
            <a-menu-item>
              <a @click="handleDetail(row)">详情</a>
            </a-menu-item>
            <a-menu-item>
              <a @click="handleDelete(row.id)" >删除</a>
            </a-menu-item>
          </a-menu>
        </a-dropdown>
      </template>
      <template v-slot:empty>
        <a-empty />
      </template>
    </vxe-grid>
    <wcs-plc-property-modal :selectObj="selectObj" ref="modalForm" @ok="modalFormOk"></wcs-plc-property-modal>
  </div>
  <!-- table区域-end -->
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { HYListMixin } from '@/mixins/HYListMixin'
  import WcsPlcPropertyModal from './modules/WcsPlcPropertyModal'
  import {getAction} from "@api/manage";

  export default {
    name: 'WcsPlcPropertyList',
    mixins:[HYListMixin, mixinDevice],
    components: {
      WcsPlcPropertyModal
    },
    data () {
      return {
        description: 'PLC点位配置表管理页面',
        selectObj:{},
        disabled: false,
        disableMixinCreated: true,
        /* 排序参数 */
        isorter: {
          column: 'wpp.createTime',
          order: 'desc',
        },
        // 表头
        columns: [
          {type: "seq", width: 50, align: "center"},//序号
          { title : '设备', align : "center", field : 'deviceName' },
          { title : '配置类型', align : "center", field : 'type_dictText' },
          { title : '读值地址', align : "center", field : 'readAddress' },
          { title : '写值地址', align : "center", field : 'writeAddress' },
          { title : '刷新时间', align : "center", field : 'refreshTime' },
          { title : '坐标', align : "center", field : 'coord' },
          { title : '工位', align : "center", field : 'station' },
          {title: '创建人', align: "center", field: 'createBy'},
          {title: '创建日期', align: "center", width: 200, field: 'createTime'},
          {title: '更新人', align: "center", field: 'updateBy'},
          {title: '更新日期', align: "center", width: 200, field: 'updateTime'},
          {title: '操作', fixed: 'right', width: 105, slots: {default: 'operate'}}
        ],
        url: {
          list: "/wcs/wcsPlcProperty/list",
          delete: "/wcs/wcsPlcProperty/delete",
          deleteBatch: "/wcs/wcsPlcProperty/deleteBatch",
          exportXlsUrl: "/wcs/wcsPlcProperty/exportXls",
          importExcelUrl: "wcs/wcsPlcProperty/importExcel",
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      refreshDetailList(){
        this.loadData();
      },
      showDetail(selectObj,disabled) {
        if(!selectObj){
          return;
        }
        this.selectObj = selectObj;
        this.disabled = disabled;
        getAction(this.url.list, {
          plcId: selectObj.id,
          pageNo: this.tablePage.currentPage,
          pageSize: this.tablePage.pageSize
        }).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records;
            this.tablePage.total = res.result.total;
            this.modalFormOk();
          } else {
            this.dataSource = null;
          }
        })
      },
      loadData() {
        getAction(this.url.list, {
          plcId: this.selectObj.id,
          pageNo: this.tablePage.currentPage,
          pageSize: this.tablePage.pageSize
        }).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records;
            this.tablePage.total = res.result.total;
          } else {
            this.dataSource = null;
          }
        })
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'popup',value:'deviceId',text:'设备', popup:{code:'wcs_device_report',field:'id',orgFields:'id',destFields:'id'}})
        fieldList.push({type:'string',value:'type',text:'配置类型',dictCode:'wcs_plc_property_type'})
        fieldList.push({type:'string',value:'coord',text:'坐标',dictCode:''})
        fieldList.push({type:'int',value:'station',text:'工位',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
